package com.sgb.kjwl.view.ui.activity.transport;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import android.view.MotionEvent;
import android.view.inputmethod.InputMethodManager;

import com.swgk.core.util.LogUtil;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityGoodsQuotedPrice3Binding;
import com.sgb.kjwl.di.transport.DaggerTransportComponent;
import com.sgb.kjwl.di.transport.TransportModule;
import com.sgb.kjwl.model.entity.transport.GoodsInfoEntity3;
import com.sgb.kjwl.view.widget.GoodsQuotedPricePopWindow3;
import com.sgb.kjwl.viewmodel.transport.GoodsQuotedPriceModel3;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.dialog.BasePopWindow;

import java.util.List;

import javax.inject.Inject;

/**
 * 找货信息首页--悬窗--参与竞价
 */
public class GoodsInfoJoinQuotedActivity3 extends AppActivity {

    @Inject
    GoodsQuotedPriceModel3 quotedPriceModel;

    private GoodsQuotedPricePopWindow3 pricePopWindow;
    private ActivityGoodsQuotedPrice3Binding binding;
    private List<GoodsInfoEntity3> quotedPriceDataList;
    private InputMethodManager im;

    public static void start(Context context){
        Intent intent = new Intent();
        intent.setClass(context, GoodsInfoJoinQuotedActivity3.class);
        context.startActivity(intent);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerTransportComponent
                .builder()
                .appComponent(appComponent)
                .transportModule(new TransportModule(GoodsInfoJoinQuotedActivity3.this)).build()
                .inject(GoodsInfoJoinQuotedActivity3.this);
    }

    @Override
    protected void initView() {
        super.initView();

        binding = DataBindingUtil.setContentView(this, R.layout.activity_goods_quoted_price3);
        binding.setViewModel(quotedPriceModel);
        binding.include.ivBack.setOnClickListener(view -> finish());
        binding.include.titleView.setText("参与竞价");

        binding.priceSelect.setOnClickListener(view -> {
            quotedPriceModel.getQuotedPriceList();
        });

        binding.quotedSure.setOnClickListener(view -> {

        });

        //报价需求列表弹窗
        pricePopWindow = new GoodsQuotedPricePopWindow3(this);
        pricePopWindow.setBgView(binding.bgPopGrayLayout);
        pricePopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object goodsInfo, Object key2, Object key3) {
                LogUtil.v("quotedPrice","name=="+((GoodsInfoEntity3)goodsInfo).getGoodsName());
                binding.priceSelect.setText(((GoodsInfoEntity3)goodsInfo).getGoodsName());
            }
        });

        im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if(null!=im){
            im.hideSoftInputFromWindow(binding.orderPrice.getWindowToken(),0);
        }
        return super.dispatchTouchEvent(ev);
    }

    @Override
    protected void init() {

    }

    public void getQuotedPriceList(List<GoodsInfoEntity3> list){
        if(null!=list && list.size()>0){
            quotedPriceDataList = list;
            showPricePopWindow();
        }
    }

    private void showPricePopWindow(){
        pricePopWindow.showPopwindowBottom(binding.quotedPriceRoot);
//        pricePopWindow.setDatas(quotedPriceDataList);
    }
}
